<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>配置首页</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css'); }
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,product_add.js,choose.js,imageup.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
</head>
<body>
<table class="content-tab" margin_float=RucqYj >
    <tr>
        <td valign="top" class="content-rt-td ">
            <form method="post"  id="frm" name="frm" enctype="multipart/form-data">
                <!--基础信息开始-->
                <div class="product-add-div">
                    <table class="table table-border table-bordered table-striped mt-20">
                        <thead>
                            <tr>
                                <th>类型名称</th>
                                <th class="text-c">
                                    <input class="btn radius btn-secondary size-S" type="button" onclick="add_type({$id})" value="添加">
                                </th>
                            </tr>
                        </thead>
                        <tbody class="ticket-type-list">
                        {loop $ticket_type $v}
                            <tr>
                                <td class="text-c">
                                    <input type="text" class="input-text w400" onchange="update_type($(this),{$v['id']})" value="{$v['kindname']}">
                                </td>
                                <td class="text-c">
                                    <input class="btn btn-default" type="button" onclick="delete_type($(this),{$v['id']})" value="删除">
                                </td>
                            </tr>
                        {/loop}
                        </tbody>
                    </table>
                </div>
            </form>
        </td>
    </tr>
</table>
<script>
    function add_type(id)
    {
        $.ajaxform({
            url:SITEURL+'ferry/admin/ferry/ajax_add_type',
            data:{id:id},
            dataType:'json',
            method:'post',
            success:function(result){
                var html = '';
                if(result.status){
                    var data = result.data;
                    html += '<tr>';
                    html += '<td class="text-c">';
                    html += '<input type="text" class="input-text w400" onchange="update_type($(this),'+data.id+')" value="'+data.kindname+'">';
                    html += '</td>';
                    html += '<td class="text-c">';
                    html += '<input class="btn btn-default" type="button" onclick="delete_type($(this),'+data.id+')" value="删除">';
                    html += '</td>';
                    html += '</tr>';
                }
                $('.ticket-type-list').prepend(html);
            }
        })
    }

    function update_type(obj,id)
    {
        var value = obj.val();
        $.ajaxform({
            url:SITEURL+'ferry/admin/ferry/ajax_update_type',
            data:{type_id:id,value:value},
            dataType:'json',
            method:'post',
            success:function(result){
                if(result.status){
                    obj.parent().parent().remove();
                }else{
                    ST.Util.showMsg(result.msg,5)
                }
            }
        })
    }

    function delete_type(obj,id)
    {
        $.ajaxform({
            url:SITEURL+'ferry/admin/ferry/ajax_delete_type',
            data:{type_id:id},
            dataType:'json',
            method:'post',
            success:function(result){
                if(result.status){
                    obj.parent().parent().remove();
                }else{
                    ST.Util.showMsg(result.msg,5)
                }
            }
        })
    }
</script>
</body>
</html>
